package com.qf.edu.controller;

import com.qf.edu.entity.Users;
import com.qf.edu.service.SetNurseService;
import com.qf.edu.service.impl.SetNurseServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

/**
 * @author:huayuzhuo
 * @email:2798866329@qq.com
 * @desc:个人信息控制类
 * @datatime: 2022/5/28 16:04
 */
@WebServlet("/nurse/setNurse")
public class SetNurseCom extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html;charset=UTF-8");

        HttpSession session = req.getSession();
        Object name = session.getAttribute("name");
        Object password = session.getAttribute("password");

        SetNurseService service = new SetNurseServiceImpl();
        List<Users> users = service.setNurseSer(name.toString(), password.toString());

        //输出所需结果
        String name1 = users.get(0).getName();
        String sex = users.get(0).getSex();
        String phone = users.get(0).getPhone();
        String idNumbers = users.get(0).getIdNumbers();
        System.out.println("个人信息查询:");
        System.out.println(name1);
        System.out.println(sex);
        System.out.println(phone);
        System.out.println(idNumbers);
        //结果给session，jsp再调用
        session.setAttribute("users",users);
        resp.sendRedirect("setNurse.jsp");

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
